home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / uupc11ys.zip / LIB / READNEXT.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  5KB  |  129 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    r e a d n e x t . c                                             */
  3. /*                                                                    */
  4. /*    Reads a spooling directory with optional pattern matching       */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Changes Copyright (c) 1990-1993 by Kendra Electronic            */
  9. /*    Wonderworks.                                                    */
  10. /*                                                                    */
  11. /*    All rights reserved except those explicitly granted by the      */
  12. /*    UUPC/extended license agreement.                                */
  13. /*--------------------------------------------------------------------*/
  14.  
  15. /*--------------------------------------------------------------------*/
  16. /*                          RCS Information                           */
  17. /*--------------------------------------------------------------------*/
  18.  
  19. /*
  20.  *    $Id: READNEXT.C 1.4 1993/04/05 04:32:19 ahd Exp $
  21.  *
  22.  *    $Log: READNEXT.C $
  23.  *     Revision 1.4  1993/04/05  04:32:19  ahd
  24.  *     Add timestamp, size to information returned by directory searches
  25.  *
  26.  *     Revision 1.3  1992/11/22  20:58:55  ahd
  27.  *     Use strpool to allocate const strings
  28.  *
  29.  */
  30.  
  31. /*--------------------------------------------------------------------*/
  32. /*                        System include files                        */
  33. /*--------------------------------------------------------------------*/
  34.  
  35. #include <stdio.h>
  36. #include <string.h>
  37. #include <stdlib.h>
  38. #include <time.h>
  39.  
  40. /*--------------------------------------------------------------------*/
  41. /*                    UUPC/extended include files                     */
  42. /*--------------------------------------------------------------------*/
  43.  
  44. #include "lib.h"
  45. #include "readnext.h"
  46. #include "uundir.h"
  47. #include "hostable.h"
  48. #include "security.h"
  49.  
  50. currentfile();
  51.  
  52. /*--------------------------------------------------------------------*/
  53. /*    r e a d n e x t                                                 */
  54. /*                                                                    */
  55. /*    Read a directory into a linked list                             */
  56. /*--------------------------------------------------------------------*/
  57.  
  58. char     *readnext(char *xname,
  59.                    const char *remote,
  60.                    const char *subdir,
  61.                    char *pattern,
  62.                    time_t *modified,
  63.                    long   *size )
  64. {
  65.    static DIR *dirp;
  66.    static char *SaveRemote = NULL;
  67.    static char remotedir[FILENAME_MAX];
  68.  
  69.    struct direct *dp;
  70.  
  71. /*--------------------------------------------------------------------*/
  72. /*          Determine if we must restart the directory scan           */
  73. /*--------------------------------------------------------------------*/
  74.  
  75.    if ( (remote == NULL) || ( SaveRemote == NULL ) ||
  76.         !equal(remote, SaveRemote ) )
  77.    {
  78.       if ( SaveRemote != NULL )   /* Clean up old directory? */
  79.       {                           /* Yes --> Do so           */
  80.          closedir(dirp);
  81.          SaveRemote = NULL;
  82.       } /* if */
  83.  
  84.       if ( remote == NULL )      /* Clean up only, no new search? */
  85.          return NULL;            /* Yes --> Return to caller      */
  86.  
  87.       if ( pattern == NULL )
  88.          pattern = "*.*";
  89.  
  90.       sprintf(remotedir,"%s/%.8s/%s",E_spooldir,remote, subdir);
  91.       if ((dirp = opendirx(remotedir,pattern)) == nil(DIR))
  92.       {
  93.          printmsg(5, "readnext: couldn't opendir() %s", remotedir);
  94.          return NULL;
  95.       } /* if */
  96.  
  97.       SaveRemote = newstr( remote );
  98.                               /* Flag we have an active search    */
  99.    } /* if */
  100.  
  101. /*--------------------------------------------------------------------*/
  102. /*              Look for the next file in the directory               */
  103. /*--------------------------------------------------------------------*/
  104.  
  105.    if ((dp = readdir(dirp)) != nil(struct direct))
  106.    {
  107.       sprintf(xname, "%s/%s", remotedir, dp->d_name);
  108.       printmsg(5, "readnext: matched \"%s\"",xname);
  109.  
  110.       if ( modified != NULL )
  111.          *modified = dp->d_modified;
  112.  
  113.       if ( size != NULL )
  114.          *size = dp->d_size;
  115.  
  116.       return xname;
  117.    }
  118.  
  119. /*--------------------------------------------------------------------*/
  120. /*     No hit; clean up after ourselves and return to the caller      */
  121. /*--------------------------------------------------------------------*/
  122.  
  123.    printmsg(5, "readnext: \"%s\" not matched", remotedir);
  124.    closedir(dirp);
  125.    SaveRemote = NULL;
  126.    return NULL;
  127.  
  128. } /*readnext*/
  129.